package es65;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class es65Demo {
	
	 static String  driver = "org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver";
	    static String elasticsearchAddress = "127.0.0.1:9200";

	    public static Properties connectionProperties(){
	        Properties properties = new Properties();
//	        properties.put("user", "test_admin");
//	        properties.put("password", "x-pack-test-password");
	        return properties;
	    }

	    public static void main(String[] args) throws SQLException {
	    //	org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcDriver
	        String address = "jdbc:es://http://" + elasticsearchAddress;
	        Properties connectionProperties = connectionProperties();
	       
	            Connection connection = DriverManager.getConnection(address, connectionProperties);
	            Statement statement = connection.createStatement();
	            ResultSet results = statement.executeQuery(
	                    "SELECT firstname, account_number FROM bank ORDER BY account_number DESC LIMIT 5");
	          while(results.next()){
	              System.out.println(results.getString("firstname"));
	          }
	      

	    }
}
